package com.ts.conch.admin.controller;

import com.ts.conch.admin.component.AutoLog;
import com.ts.conch.common.result.CommonResult;
import com.ts.conch.entity.TsMenu;
import com.ts.conch.service.ItsMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @ClassName: MenuController
 * @Decription: 此处填写类文件说明
 * @Author: IDai
 * @Date: 2021-09-13 15:11 星期一
 **/
@RestController
@RequestMapping(value = "/menu")
@Api(tags = "[菜单管理] - 控制层")
public class TsMenuController {

    @Autowired
    private ItsMenuService menuService;

    @ApiOperation(value = "添加菜单")
    @RequestMapping(value = "/create.ts", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "title", value = "菜单名称", example = "权限"),
            @ApiImplicitParam(name = "parentId", value = "上级id", example = "0"),
            @ApiImplicitParam(name = "name", value = "前端名称", example = "权限"),
            @ApiImplicitParam(name = "icon", value = "前端图标", example = "product-add"),
            @ApiImplicitParam(name = "hidden", value = "是/否隐藏", example = "0:否,1:是"),
            @ApiImplicitParam(name = "sort", value = "排序", example = "1")
    })
    @AutoLog(value = "添加菜单", operateType = "1")
    public CommonResult<?> create(@RequestBody TsMenu menu) {
        return menuService.create(menu);
    }

    @ApiOperation(value = "修改菜单")
    @RequestMapping(value = "/update.ts", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "菜单id", example = "1"),
            @ApiImplicitParam(name = "title", value = "菜单名称", example = "权限"),
            @ApiImplicitParam(name = "parentId", value = "上级id", example = "0"),
            @ApiImplicitParam(name = "name", value = "前端名称", example = "权限"),
            @ApiImplicitParam(name = "icon", value = "前端图标", example = "product-add"),
            @ApiImplicitParam(name = "hidden", value = "是/否隐藏", example = "0:否,1:是"),
            @ApiImplicitParam(name = "sort", value = "排序", example = "1")
    })
    @AutoLog(value = "修改菜单", operateType = "2")
    public CommonResult<?> update(@RequestBody TsMenu menu) {
        return menuService.update(menu);
    }

    @ApiOperation("[菜单管理] - 菜单详情")
    @RequestMapping(value = "/getMenu.ts", method = RequestMethod.POST)
    @ApiImplicitParam(name = "id", value = "菜单id", example = "1")
    @AutoLog(value = "[菜单管理] - 菜单详情", operateType = "4")
    public CommonResult<?> getItem(@RequestBody Map<String, Object> params) {
        String id = (String) params.get("id");
        return menuService.getItem(id);
    }

    @ApiOperation("[菜单管理] - 删除菜单")
    @RequestMapping(value = "/delete.ts", method = RequestMethod.POST)
    @ApiImplicitParam(name = "id", value = "菜单id", example = "1")
    @AutoLog(value = "[菜单管理] - 删除菜单", operateType = "3")
    public CommonResult<?> delete(@RequestBody Map<String, Object> params) {
        String id = (String) params.get("id");
        return menuService.delete(id);
    }

    @ApiOperation("[菜单管理] - 分页菜单列表")
    @RequestMapping(value = "/list.ts", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", example = "1"),
            @ApiImplicitParam(name = "size", value = "每页展示数量", example = "10"),
            @ApiImplicitParam(name = "parentId", value = "菜单的父id", example = "0")
    })
    @AutoLog(value = "[菜单管理] - 分页菜单列表", operateType = "5")
    public CommonResult<?> list(@RequestBody Map<String, Object> params) {
        return menuService.list(params);
    }

    @ApiOperation("[菜单管理] - 树状菜单列表")
    @RequestMapping(value = "/treeList.ts", method = RequestMethod.POST)
    @AutoLog(value = "[菜单管理] - 树状菜单", operateType = "5")
    public CommonResult<?> treeList() {
        return menuService.treeList();
    }

    @ApiOperation("[菜单管理] - 修改菜单状态")
    @RequestMapping(value = "/updateHidden.ts", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "菜单的id", example = "1"),
            @ApiImplicitParam(name = "hidden", value = "是/否隐藏", example = "0")
    })
    @AutoLog(value = "[菜单管理] - 修改菜单状态", operateType = "2")
    public CommonResult<?> updateHidden(@RequestBody Map<String, Object> params) {
        return menuService.updateHidden(params);
    }

}
